/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inventory;

import entity.entityItem;

/**
 *
 * @author miker
 */
public class inventory {
    private static final int mass_limit = 10;
    entityItem grabbed = null;
    private entityItem[] content = new entityItem[32];
    private cBelt belt = null;
    //private toolpack p = null;

    public float getMass() {
            float mass = 0;

            for(int i=0; i<content.length; i++) {
                    if(content[i] != null) {
                            mass += content[i].getMass();
                    }
            }

            if(belt != null) {
                    for(int i=0; i<belt.getSize(); i++) {
                            if(belt.getItem(i) != null) {
                                    mass += content[i].getMass();
                            }

                    }
            }


            return mass;
    }

    public int getFirstEmptyslot() {
            for(int i=0; i<content.length; i++) {
                    if(content[i] == null) {
                            return i;
                    }
            }
            return -1;
    }

    public entityItem getGrabbedItem() {
            return grabbed;
    }

    public void grabItem(int i) {
            if(content[i] != null) {
                    if(grabbed ==null) {
                            grabbed = content[i];
                    } else {
                            entityItem extr = grabbed;
                            grabbed = content[i];
                            content[i] = extr;
                    }
            }
    }
    public void putItem(int i) {
            if(grabbed != null) {
                    if(content[i] == null) {
                            content[i] = grabbed;
                    } else {
                            entityItem extr = grabbed;
                            grabbed = content[i];
                            content[i] = extr;
                    }
            }
    }

    public void setItem(int i, entityItem e) {
            content[i] = e;
    }

    public entityItem getItem(int i) {
            return content[i];
    }

    private float getMasslimit() {
            float limit = mass_limit;
            if(belt!= null) {
                    limit += cBelt.mass_limit;
            }

            return limit;
    }

    public boolean canAdd (int m) {
            return m<getMasslimit();
    }
}

